package com.assignwork.service.impl;

import com.assignwork.dto.ImportDataDTO;
import com.assignwork.entity.ShipDynamic;
import com.assignwork.mapper.ShipDynamicMapper;
import com.assignwork.service.IShipDynamicService;
import com.assignwork.vo.GroupDayStatPlanVO;
import com.assignwork.vo.ShipDynamicVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.tool.utils.Func;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ShipDynamicServiceImpl extends BaseServiceImpl<ShipDynamicMapper, ShipDynamic> implements IShipDynamicService {

    @Override
    public List<ShipDynamicVO> listShipDynamic(BladeUser bladeUser, Query query, ImportDataDTO dto) {
        LambdaQueryWrapper<ShipDynamic> eq = new QueryWrapper<ShipDynamic>()
                .lambda()
                .eq(ShipDynamic::getPlanDate, dto.getPlanDate());
        Condition.addOrder(eq, query);
        List<ShipDynamic> list = this.list(eq);

        List<ShipDynamicVO> res = new ArrayList<>();

        for (ShipDynamic shipDynamic : list) {
            ShipDynamicVO copy = Func.copy(shipDynamic, ShipDynamicVO.class);
            res.add(copy);
        }

        res.sort((a, b) -> {
            return a.getData().getStatTime().after(b.getData().getStatTime()) ? 0 : -1;
        });

        return res;
    }

}
